var Shade = {
    open: function(color){
        $('html').css('overflow-y', 'hidden');
        if($("#bgDiv").length > 0){
            return;
        }else{
            var bodyWidth = document.documentElement.clientWidth;
            var bodyHeight = Math.max(document.documentElement.clientHeight, document.documentElement.scrollHeight);
            var bgObj = document.createElement("div" );
            bgObj.setAttribute( 'id', 'bgDiv' );
            bgObj.style.position = "absolute";
            bgObj.style.top = "0";
            bgObj.style.background = color || "#000000";
            bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75" ;
            bgObj.style.opacity = "0.7";
            bgObj.style.left = "0";
            bgObj.style.width = bodyWidth + "px";
            bgObj.style.height = bodyHeight + "px";
            bgObj.style.zIndex = "999"; //设置zindex属性
            document.body.appendChild(bgObj); //添加遮罩
        }
    },
    close: function(){
        $('html').css('overflow-y', '');
        if($("#bgDiv").length > 0)
            $( "#bgDiv").fadeOut("fast", function(){$(this).remove()});
    }

}
var AlertBox = {
    /**
     * confirm提示框
     * @param content 提示内容
     * @param btnName ok,cancel
     * @param callbackOk 确认操作
     * @param callbackNo 取消操作
     */
    showConfirm : function (text, btnName, callbackOk, callbackNo, hasCloud){
        if(!arguments[4] || hasCloud) Shade.open();
        var boxWidth = 250,
            boxHeight = 142;
        var ok_style = 'height:50px; display: block; float: left; line-height: 50px; width: 124px;'
        var cancel_style = 'display: block; height: 50px; float: left; width: 124px; line-height: 50px; border-right: 1px solid #34495E;'
        var alertDiv = document.createElement('div');
        alertDiv.setAttribute('id', 'alertBox');
        alertDiv.style.width = boxWidth + 'px';
        alertDiv.style.height = boxHeight + 'px';
        var textDiv = document.createElement('div');
        textDiv.setAttribute('id', 'txt');
        textDiv.style.height = '90px';
        textDiv.style.width = boxWidth + 'px';
        textDiv.style.padding = '10px 10px 0px';
        textDiv.style.display = 'table-cell';
        textDiv.style.verticalAlign = 'middle';
        textDiv.innerHTML = text;
        var btnDiv = document.createElement('div');
        btnDiv.style.height = '50px';
        btnDiv.setAttribute('style', 'border-top: 1px solid #34495E;');
        var okBtn = document.createElement('span');
        okBtn.innerHTML = btnName?btnName.ok:'确定';
        okBtn.setAttribute('style', ok_style);
        okBtn.onclick = function(){
            callbackOk();
        }
        var noBtn = document.createElement('span');
        noBtn.setAttribute('style', cancel_style);
        noBtn.innerHTML = btnName?btnName.cancel:'取消';
        noBtn.onclick = function(){
            callbackNo();
        }
        btnDiv.appendChild(noBtn);
        btnDiv.appendChild(okBtn);
        alertDiv.appendChild(textDiv);
        alertDiv.appendChild(btnDiv);
        alertDiv.style.top = document.body.scrollTop + (document.documentElement.clientHeight-boxHeight)/2 + 'px';
        alertDiv.style.left = ($(window).width()-boxWidth) / 2 +'px';
        document.body.appendChild(alertDiv);
    },
    /**
     * 提示弹出卡
     * @param content 内容
     * @param cloud 是否遮蔽
     * @param callback 操作
     */
    showAlert : function showAlert(text, hasCloud, callback, btnName){
        if(hasCloud) Shade.open();
        var boxWidth = 250;
        var boxHeight = 150;
        var btn_Name = btnName || '确 定';
        var ok_style = 'display: block; height: 50px; float: left; width: 250px; line-height: 50px;'
        var alertDiv = document.createElement('div');
        alertDiv.setAttribute('id', 'alertBox');
        alertDiv.style.width = boxWidth + 'px';
        alertDiv.style.height = boxHeight + 'px';
        var textDiv = document.createElement('div');
        textDiv.setAttribute('id', 'txt');
        textDiv.style.height = '100px';
        textDiv.style.width = boxWidth + 'px';
        textDiv.style.padding = '10px 10px 0px';
        textDiv.style.display = 'table-cell';
        textDiv.style.verticalAlign = 'middle';
        textDiv.innerHTML = text;
        var btnDiv = document.createElement('div');
        btnDiv.style.height = '50px';
        btnDiv.setAttribute('style', 'border-top: 1px solid #34495E;');
        var okBtn = document.createElement('span');
        okBtn.innerHTML = btn_Name;
        okBtn.setAttribute('style', ok_style);
        okBtn.onclick = function(){
            callback();
        }
        btnDiv.appendChild(okBtn);
        alertDiv.appendChild(textDiv);
        alertDiv.appendChild(btnDiv);
        alertDiv.style.top = document.body.scrollTop ? boxHeight + document.body.scrollTop : ($(window).height()-boxHeight)/2 +'px';
        alertDiv.style.left = ($(window).width()-boxWidth) / 2 +'px';
        document.body.appendChild(alertDiv);
    },

    closeAlertBox : function(){
        $('#alertBox').remove();
        Shade.close();
    },

    showTip : function(content, time){
        var boxWidth = 130;
        var boxHeight = 50;
        var css_style = 'position:absolute;' +
            'background-color: rgba(0, 0, 0, 0.5);'+
            'text-align: center;' +
            'line-height: 50px;' +
            'min-width: '+boxWidth+'px;' +
            'border-radius: 3px;' +
            'padding: 0 10px;'+
            'z-index: 20001;'
        var tipDiv = document.createElement('div')
        tipDiv.setAttribute('id', 'tipBox')
        tipDiv.setAttribute('style', css_style)
        //tipDiv.style.width = boxWidth + 'px';
        tipDiv.style.height = boxHeight + 'px';
        tipDiv.style.color = '#FFFFFF';
        //tipDiv.style.top = document.body.scrollTop ? boxHeight + document.body.scrollTop : ($(window).height()-boxHeight)/2 +'px';
        tipDiv.style.top = document.body.scrollTop + (document.documentElement.clientHeight-boxHeight)/2 + 'px';
        tipDiv.style.left = ($(window).width()-boxWidth) / 2 +'px';
        tipDiv.innerHTML = content;
        document.body.appendChild(tipDiv);
        $('#tipBox').on('click', function(event){
            $(event.currentTarget).remove();
        })
        if(!time){
            setTimeout(function(){
                $('#tipBox').fadeOut(function(){
                    $('#tipBox').remove();
                });
            }, 1500)
        }
    },

    hideTip : function(){
        $('#tipBox').remove();
    }
}